package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealDish;
import com.itheima.reggie.entity.SetmealDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @Select("SELECT * FROM Setmeal where category_id = #{id} and status = 1 ;")
    List<Setmeal> findSetmealByCategoryId (Long id );

    //添加套餐
    @Options(useGeneratedKeys = true , keyProperty = "id")
    @Insert("INSERT INTO setmeal VALUES ( null , #{categoryId} , #{name} , #{price} , #{status} ,  0  , #{description} , #{image} , #{createTime} ,  #{updateTime}  , #{createUser}  , #{updateUser} , 0 );")
    void addSetmeal(SetmealDto setmealDto);

    //这是添加套装，然后将套餐类的菜品添加到套餐和菜品联合表中
    @Insert("INSERT INTO setmeal_dish VALUES ( null , #{setmealId} , #{dishId} , #{name} , #{price} , #{copies} , #{sort} , #{createTime} , #{updateTime} , #{createUser}  , #{updateUser} , 0  );")
    void addSetmealDish(SetmealDish setmealDish);

    //获取套餐集合
    List<Setmeal> findAll(String name);

    //查看id集合中处于出售的套餐
    @Select( " SELECT * FROM setmeal where id = #{id} and status = 1 ;")
    Setmeal findOnSaleById( Long id );

    //删除套餐
    @Delete(" DELETE FROM setmeal WHERE id = #{id};")
    void deleteById(Long id);

    //删除套餐菜品连接表里的数据
    @Delete( "DELETE FROM setmeal_dish WHERE setmeal_id = #{id};")
    void deleteSetmealDishById(Long id);

    //查看套餐根据分类
    @Select( "SELECT * FROM setmeal where category_id = #{categoryId };")
    List<Setmeal> findByCategoryId( String categoryId );
}
